from time import sleep

from appium.webdriver.common.appiumby import AppiumBy

from appium_qiyeweixin.page_object.public.nav_menu import NavMenu


# 添加成员页面
class AddMemberPage(NavMenu):

    __MANUAL_INPUT = (AppiumBy.XPATH, "//*[@text='手动输入添加']")
    __BLACK_ADDRESS_BOOK = (AppiumBy.XPATH, "//*[@text='添加成员']/../../../../android.widget.TextView")
    __CONFIRM_TOAST = (AppiumBy.XPATH, "//*[@text='添加成功']")

    # 切换到手动添加页面
    def switch_manual_input(self):
        self.do_ele_click(self.__MANUAL_INPUT)

        from appium_qiyeweixin.page_object.manual_input_page import ManualInputPage
        return ManualInputPage(self.driver)

    # 获取确认弹框
    def confirm_toast(self):
        element = self.do_find(self.__CONFIRM_TOAST)

        return element.text

    # 返回通讯页
    def black_address_book(self):
        sleep(1)
        self.do_ele_click(self.__BLACK_ADDRESS_BOOK)

        from appium_qiyeweixin.page_object.address_book_page import AddressBookPage
        return AddressBookPage(self.driver)
